<#include "/default/layout/account.htm"/> 
<@layout>
		<div class="block-center mt-xl wd-xl">
			<div class="panel panel-dark panel-flat">
				<div class="panel-body" id="forgotPasswordPage">
					<form id="inputForm">
						<p class="text-center pv">请填写您的登录邮箱来收取密码重置邮件</p>
						<div class="form-group has-feedback">
							<input id="mail" name="mail" type="mail" placeholder="输入邮箱" class="form-control" data-parsley-required-message="请输入邮箱地址" data-parsley-type-message="请输入正确的邮箱地址" required="required" /> 
							<span class="fa fa-envelope form-control-feedback text-muted"></span>
						</div>
						<p class="text-center" style="color: red" id="message" >${message!}</p>
						<button id="sendEmailButton" onclick="sendEmail();" class="btn btn-block btn-primary mt-lg">发送重置邮件</button>
					</form>
					<p></p>
               		<a href="${ctx}/login?redirect=${RequestParameters.redirect}" class="btn btn-block btn-default">返回登录</a>
				</div>
			</div>
			<div class="p-lg text-center">
			</div>
		</div>
	
	
	<script type='text/javascript' >
		function sendEmail() {
			var redirect = '${redirect}';
			var mail = $("#mail").val();
			$('#sendEmailButton').attr("disabled", true);
			$.ajax({                                               
				url: '${ctx}/user/sentmail', 
				data:{'redirect':redirect,'mail':mail},
				type: 'GET',
				contentType: "application/json;charset=UTF-8",		
				dataType: 'text',
				success: function(data){
					$("#message").text("");
					var resultData = $.parseJSON(data);
					if(resultData.code == 200 || resultData.status == 'success'){
						var t=200;//设定跳转的时间 
						var time = setInterval(
								function (){  
								    $("#sendEmailButton").text("邮件已发送 "+t+" 秒后重试"); // 显示倒计时 
								    t--; // 计数器递减 
								    if(t==0){ 
								    	clearInterval(time);
								    	$('#sendEmailButton').removeAttr("disabled");
								    	$("#sendEmailButton").text("再次发送重置邮件");
								    } 
								} 
						,1000); //启动1秒定时 
					}else{
						$("#message").text(resultData.message);
				    	$('#sendEmailButton').removeAttr("disabled");
				    	$("#sendEmailButton").text("发送重置邮件");
					}
				},error:function(xhr){alert('错误了\n\n'+xhr.responseText)}//回调看看是否有出错
			});
		}
	</script>
	
</@layout>